package com.github.cyf.junkFile.controller;

import com.github.cyf.common.module.Rs;
import com.github.cyf.junkFile.entity.UploadResult;
import com.github.cyf.junkFile.service.JunkFileService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;

/**
 * @author chenyifan
 * @create 2024-03-27 21:36
 */
@RestController
@Api(tags = "垃圾文件处理")
@RequestMapping("/junkFile")
@RequiredArgsConstructor
public class JunkFileController {

    private final JunkFileService fileService;

    @PostMapping("/upload")
    @ApiOperation(value = "01_上传文件")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "files", value = "上传的文件", dataTypeClass = MultipartFile.class, required = true)
    })
    public Rs upload(@RequestPart("files") MultipartFile[] multipartFiles) {
        List<UploadResult> list = fileService.uploadFile(multipartFiles);
        return Rs.ok("上传成功").setData(list);
    }

    @PostMapping("/confirm")
    @ApiOperation(value = "02_确认需要保存的文件")
    @ApiOperationSupport(order = 2)
    public Rs confirm(@RequestBody List<String> filePathList) {
        fileService.confirm(filePathList);
        return Rs.ok("保存成功");
    }

    @GetMapping("/result")
    @ApiOperation(value = "03_查看结果")
    @ApiOperationSupport(order = 3)
    public Rs getResult() {
        Map<String, Object> map = fileService.getResult();
        return Rs.ok("查看结果").setData(map);
    }
}
